#include "clasaclient.h"
#include "clasemasini.h"

Client::Client()
{ char *nm = (char*)malloc(20 * sizeof(char));
  char *pr = (char*)malloc(20 * sizeof(char));
  int v;

  //lista de masini a clientului e goala la inceput
  this->first = NULL;
  this->last = NULL;
  
  this->nume = (char*)malloc(20 * sizeof(char));
  this->prenume = (char*)malloc(20 * sizeof(char));

	printf("Introdu nume client:\n");
    scanf("%s", nm);
	printf("Introdu prenume client:\n");
	scanf("%s", pr);
	printf("Introdu varsta client:\n");
	scanf("%d", &v);

	strcpy(this->nume, nm);
	strcpy(this->prenume, pr);
	this->varsta = v;
}

void Client::Add_masina(Car *m)
{
   listamasini *nod = new listamasini();
   nod->masina = m;
   nod->next = NULL;

   if(this->first ==NULL)
   {
	  
	   this->first = nod;
	   this->last = nod;
	  
   }
   else
   {
	   this->last->next = nod;
	   this->last = this->last->next; 
	    
   }

}


void Client::Print_Cars()
{
   listamasini *nod = this->first;

   while(nod != NULL)
   {
	   nod->masina->PrintCar();
	   
	   nod=nod->next;
   }
}

void Client::Delete_masina(Car *m)
{
   listamasini *nod = this->first;

   if(nod->masina == m) 
	   this->first=nod->next;
   else
   {
    while(nod->next != NULL)
    {
      if(nod->next->masina == m)
       break;

	  nod=nod->next;
    }
   //nod->next e nodul pe care dorim sa-l stergem

     if(nod->next->next!=NULL) //daca nu e ultima in lista
     {  
       nod->next = nod->next->next;
     }
	 else
	 { 
	     nod->next = NULL;
	 }
   }
}






